/*-----------------------------------------------------------------------------
 * event.h - Event Manager (EVM) library API.  The EVM library implements a 
 * simple message passing interface for multiple threads in a multi-threaded 
 * process.  It also provides a timer library implementation on top of the 
 * message passing facility.
 *            
 * Forhad Ahmed, Jun 2009
 *-----------------------------------------------------------------------------
 */

#ifndef _EVENT_H_
#define _EVENT_H_


/*
 * 
 *
 */


/*
 * event_manager - opaque type for event_manager_t
 */
typedef struct event_manager_t event_manager;


/*
 * event_manager_create() - create a per-thread memory context (event manager)
 * for receiving messages from other threads.  The evm handle returned by this
 * function can be used by other threads to send events to the current thread.
 */
event_manager*
event_manager_create(void);


/*
 * event_attach() - attach a callback function to an evm for handling a certain
 * type of event.
 *
 *     ARGUMENT:   
 */
int
event_attach(event_manager *evm, int code, event_handler_fn callback);


/*
 * event_send() - send an event to a specific evm.
 *
 *  
 *
 */
int
event_send(event_manager *evm, int code, void *data);


/*
 * event_recv() - receive an event from the evm's event queue.  If the queue is
 * empty, this function blocks until there is an event.  Usually, this function
 * is put inside a while loop to create a thread's main event loop.
 * 
 */
int 
event_recv(event_manager *evm, int *code, void *data);


/* 
 * event_timer_create() - create a timer with a specified code and data and 
 * associate it with an evm.  An event with that code and data will be sent to
 * the evm upon the expiry of that timer. This, in conjunction with the
 * event_attach() api can be used to implement callback functions for timers.
 */
int
event_timer_create(event_manager *evm, int code, void *data);


#endif /* _EVENT_H_ */


